/****************************************************************

kernel/driver/fat.h
FAT header for AWOS Kernel

****************************************************************/

#ifndef ___DRIVER_FAT_H_
#define ___DRIVER_FAT_H_

/** OEM -- MS- and PC-DOS 3.3 **/
#define FAT_OEM_DOS3	"IBM 3.3 "
/** OEM -- MS-DOS 5.0 or higher, including Windows NT/2000 **/
#define FAT_OEM_DOS	"MSDOS5.0"
/** OEM -- Windows 95 original or OSR1 **/
#define FAT_OEM_W95	"MSWIN4.0"
/** OEM -- Windows 95b or Windows 98 **/
#define FAT_OEM_W98	"MSWIN4.1"
/** OEM -- OS/2 **/
#define FAT_OEM_OS2	"IBM 20.0"

#define FAT_ATT_READONLY  0x01
#define FAT_ATT_HIDDEN    0x02
#define FAT_ATT_SYSTEM    0x04
#define FAT_ATT_VOLLABEL  0x08	//is this really used?
#define FAT_ATT_SUBDIR    0x10
#define FAT_ATT_ARCHIVE   0x20
#define FAT_ATT_RESERVED  0x40	//knowing Micro$oft, I better support reserved attributes
#define FAT_ATT_RESERVED2 0x80	//^^same as above^^

#define FAT_NTD_DIRTY	0x01	//dirty flag
#define FAT_NTD_SURFACE	0x02	//Windows NT was told by user to perform surface scan on next boot

/*! \struct FsFat16Vbr
 * Volume Boot Record struct for FAT12/16.
 */
struct FsFat16Vbr
{
	/** jump to boot -- normally 0xEB3C90 **/
	char jmpboot[3];
	/** OEM name.  normally MSDOS5.0, MSWIN4.0, or MSWIN4.1 **/
	char oem[8];
	/** bytes per sector -- normally 512 **/
	char bps[2];
	/** sectors per cluster.  must be 2^x > 0 **/
	char spc;
	/** number of sectors reserved for boot records -- normally 1 **/
	char rsvdsecs[2];
	/** number of FAT structures -- normally 2 **/
	char fatcount;
	/** count of entries in root directory -- normally 512 **/
	char rootcount[2];
	/** 16-bit count of sectors -- if 0, see sectors32 **/
	char sectors16[2];
	/** media descriptor -- 0xF8 for fixed disks **/
	char media;
	/** 16-bit count of sectors occupied by one FAT structure **/
	char fatsize[2];
	/** sectors per track -- normally 63 on fixed disks **/
	char secstrack[2];
	/** number of heads on disk -- 255 on fixed disks **/
	char heads[2];
	/** hidden sectors preceding this volume -- 63 first 1st volume **/
	char hiddensecs[4];
	/** 32-bit count of total sectors on volume.  if 0, see sectors16 **/
	char sectors32[4];
	/** drive number -- 0x00 for floppies, 0x80 for fixed disks **/
	char drive;
	/** NT dirty byte -- use FAT_NTD_ defines **/
	char ntdirty;
	/** extended boot signature -- if 0x29, next three fields are valid. **/
	char extsig;
	/** volume serial number **/
	char serial[4];
	/** volume label **/
	char label[11];
	/** file system type -- normally FAT12, FAT16 or FAT **/
	char systype[8];
	/** boot code **/
	char bootcode[448];
	/** signature -- normally 0x55 0xAA **/
	char sig[2];
};

/*! \struct FsFat32Vbr0
 * Volume Boot Record (sector 0) struct for FAT32.
 */
struct FsFat32Vbr0
{
	/** jump to boot -- normally 0xEB3C90 **/
	char jmpboot[3];
	/** OEM name.  normally MSDOS5.0, MSWIN4.0, or MSWIN4.1 **/
	char oem[8];
	/** bytes per sector -- normally 512 **/
	char bps[2];
	/** sectors per cluster.  must be 2^x > 0 **/
	char spc;
	/** number of sectors reserved for boot records -- normally 1 **/
	char rsvdsecs[2];
	/** number of FAT structures -- normally 2 **/
	char fatcount;
	/** count of entries in root directory -- normally 512 **/
	char rootcount[2];
	/** 16-bit count of sectors -- 0 for FAT32 volumes **/
	char sectors16[2];
	/** media descriptor -- 0xF8 for fixed disks **/
	char media;
	/** 16-bit count of sectors occupied by FAT -- 0 for FAT32 **/
	char fatsize[2];
	/** sectors per track -- normally 63 on fixed disks **/
	char secstrack[2];
	/** number of heads on disk -- 255 on fixed disks **/
	char heads[2];
	/** hidden sectors preceding this volume -- 63 first 1st volume **/
	char hiddensecs[4];
	/** 32-bit count of total sectors -- must be >0 for FAT32 **/
	char sectors32[4];
	/** FAT32 extended flags **/
	char ext32;
	/** version number of FAT32 volume -- high byte is major, low byte is minor.  normally 0x00 0x00 **/
	char version[2];
	/** cluster number of start of root directory -- normally 2 **/
	char rootstart[4];
	/** sector number of extended FSInfo sector -- normally 1 **/
	char fsinfo[2];
	/** sector number of backup copy of boot record -- normally 6 **/
	char backup[2];
	/** reserved -- should be 0 **/
	char reserved[12];
	/** drive number -- 0x00 for floppies, 0x80 for fixed disks **/
	char drive;
	/** NT dirty byte -- use FAT_NTD_ defines **/
	char ntdirty;
	/** extended boot signature -- if 0x29, next three fields are valid. **/
	char extsig;
	/** volume serial number **/
	char serial[4];
	/** volume label **/
	char label[11];
	/** file system type -- normally FAT12, FAT16 or FAT **/
	char systype[8];
	/** boot code **/
	char bootcode[448];
	/** signature -- normally 0x55 0xAA **/
	char sig[2];
};

/*! \struct FsFat32Vbr1
 * Volume Boot Record (sector 1) struct for FAT32.
 */
struct FsFat32Vbr1
{
	/** first signature -- validation code -- 0x52526141 **/
	long firstsig;
	/** reserved -- should be 0 **/
	char reserved[480];
	/** structure signature -- validation code -- 0x72724161 **/
	long signature;
	/** count of free clusters **/
	long freecount;
	/** next free cluster **/
	long nextfree;
	/** reserved -- should be 0 **/
	char reserved2[12];
	/** trailing signature -- validation code -- 0x000055AA **/
	long lastsig;
};

/*! \struct FsFat32Vbr2
 * Volume Boot Record (sector 2) struct for FAT32.
 */
struct FsFat32Vbr2
{
	/** boot code **/
	char boot[520];
	/** signature -- validation code -- 0x55AA **/
	char signature[2];
};

struct FsFatEntry
{
	/** file name (e.g. awos    ) -- space padded to be 8 chars **/
	char filename[8];
	/** file extension (e.g. doc)  -- no dot, space padded**/
	char ext[3];
	/** attribute byte.  see above for types **/
	char attrib;
	/** reserved attributes **/
	char reserved[10];
	/** 1 word time **/
	char mod_time[2];
	/** 1 word date **/
	char mod_date[2];
	/** 1 word starting cluster **/
	char start_cluster[2];
	/** 1 dword size of entry (file/dir) in bytes **/
	char size[4];
};

#endif //#ifndef ___DRIVER_FAT_H_